package trism.trifield.model.slots {
	import flash.events.MouseEvent;
	import assets.SlotMc;

	import trism.game.model.common.stat.cells.CellItem;
	import trism.trifield.event.SlotEvent;

	import flash.display.MovieClip;
	import flash.events.EventDispatcher;
	/**
	 * @author Samoiloff  http://samoiloff.com/
	 */
	public class Slot extends EventDispatcher {
		
		private var _mc			: SlotMc;
		
		private var _type:int;
		
		private var _cellItem : CellItem;
		
		public function Slot() {
			_mc = new SlotMc();
			_mc.mouseEnabled = false;
			_mc.tf.mouseEnabled = false;
			_mc.tf.visible =false;
			
			_mc.triangleMc.scaleX = _mc.triangleMc.scaleY = .5;
			
			_mc.triangleMc.addEventListener(MouseEvent.MOUSE_DOWN, dispatchEvent);
			_mc.triangleMc.addEventListener(MouseEvent.MOUSE_UP, dispatchEvent);
		}
		
		public function destroy():void {
			_mc.triangleMc.removeEventListener(MouseEvent.MOUSE_DOWN, dispatchEvent);
			_mc.triangleMc.removeEventListener(MouseEvent.MOUSE_UP, dispatchEvent);
			
			_mc = null;
			_cellItem = null;
		}
		
		public function set type(type : int) : void {
			_type = type;
			_mc.triangleMc.gotoAndStop(_type); 
		}
		
		public function get type() : int {
			return _type;
		}
		
		public function get cellItem() : CellItem {
			return _cellItem;
		}

		public function set cellItem(cellItem : CellItem) : void {
			if (_cellItem != cellItem) {
				_cellItem = cellItem;
				
				_mc.x = _cellItem.xCoord;
				_mc.y = _cellItem.yCoord;

				_mc.triangleMc.rotation = _cellItem.headRight ? 90 : 270;
				_mc.tf.text = _cellItem.x + ":" + cellItem.y;
				
				trace("Slot.cellItem() : " + _mc.x +":" + _mc.y);
				
				dispatchEvent(new SlotEvent(SlotEvent.CELL_ITEM_CHANGED, this));
			}
		}
		
		public function get mc() : MovieClip {
			return _mc;
		}
		
		
		
	}
}
